<?=view('header.html')?>

<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">

            <div class="layui-card">
                <div class="layui-card-header">搜索参数</div>
                <div class="layui-card-body">
                    <form class="layui-form" id="searchForm">
                        
                        <div class="layui-inline">
                            <div class="layui-form-mid">管理员:</div>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">日期：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="day" id="day" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-blue" lay-submit lay-filter="ams_search">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary" lay-submit lay-filter="ams_reset">重置</button>
                        </div>
                    </form>
                </div>
            </div>



            <div class="layui-card">

                <div class="layui-card-header">操作记录</div>

                <div class="layui-card-body">

                    <script type="text/html" id="toolbarOption">
                        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delAll">删除</a>
                    </script>

                    <table id="listTable" lay-filter="listTable"></table>

                </div>
            </div>
        </div>
    </div>
    <?=view('footer.html')?>

    <script type="text/javascript">
        layui.use(['form', 'jquery', 'layer', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                table = layui.table;
            
            /**index**/

            //数据初始化
            var tableInit = table.render({
                elem: '#listTable',
                toolbar: "#toolbarOption",
                defaultToolbar: [],
                title: '管理员操作',
                url: adminpath + 'admin/system/oplog',
                method: 'post',
                cols: [
                    [{
                        type: 'checkbox'
                    }, {
                        field: 'id',
                        title: 'ID',
                        width: 100,
                        unresize: true,
                        sort: true
                    }, {
                        field: 'username',
                        width: 160,
                        title: '用户名',
                    }, {
                        field: 'action',
                        title: '操作描述'
                    }, {
                        field: 'inputtime',
                        title: '操作时间'
                    }, {
                        field: 'ip',
                        title: 'IP'
                    }]
                ],
                page: {
                    layout: ['prev', 'page', 'next', 'count'],
                    groups: 5,
                    first: true,
                    last: true
                },
                response: {
                    statusCode: 0,
                    countName: 'count'
                },
                parseData: function (res) {
                    return {
                        'code': res.code,
                        'data': res.data.data,
                        'count': res.data.total
                    };
                }
            });


            //表头工具栏
            table.on('toolbar(listTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                var ids = [];
                $.each(data, function (i, v) {
                    ids.push(v.id);
                })

                switch (obj.event) {

                    case 'del':
                        layer.confirm('确定要删除这些？', function (index) {
                            $.post(adminpath + '/service/del', {
                                ids: ids
                            }, function (res) {
                                if (res.code == 0) {
                                    layer.msg('操作成功', {
                                        icon: 1,
                                        time: 1500
                                    });
                                } else {
                                    layer.msg(res.msg, {
                                        icon: 5,
                                        anim: 6
                                    });
                                }
                                tableInit.reload();
                            }, 'json');
                            layer.close(index);
                        });
                        break;

                }
                ;
            });

            //监听表格行操作
            table.on('tool(listTable)', function (obj) {
                var data = obj.data;
                var id = data.id
                switch (obj.event) {
                    case 'edit':
                        var title = '修改服务(#' + id + ')';
                        var url = adminpath + 'admin/system/edit?id=' + id;
                        open_parent_tab(title, url);
                        break;

                    case 'del':
                        layer.confirm('确定要删除吗？', function (index) {
                            $.post(adminpath + '/service/del', {
                                ids: [id]
                            }, function (res) {
                                if (res.code == 0) {
                                    obj.del();
                                    layer.msg(res.msg, {
                                        icon: 1,
                                        time: 1500
                                    }, function () {
                                        tableInit.reload();
                                    });
                                } else {
                                    layer.msg(res.msg, {
                                        icon: 5,
                                        anim: 6,
                                        time: 1500
                                    }, function () {
                                        tableInit.reload();
                                    });
                                }
                            }, 'json');
                        });
                        break;
                }
            });

            //搜索条件

            //标题搜索
            form.on('submit(searchTitle)', function (data) {
                var value = data.field['title'];
                tableInit.reload({
                    where: {
                        title: value
                    },
                    page: {
                        curr: 1
                    }
                });
            });


            //发布状态
            form.on('radio(searchSubmitStatus)', function (data) {
                var value = data.value;
                tableInit.reload({
                    where: {
                        submitstatus: value
                    },
                    page: {
                        curr: 1
                    }
                });
            });

            //搜索
            form.on('submit(ams_search)', function (data) {
                var field = data.field;
                tableInit.reload({
                    where: {
                        username: field.username
                        , day: field.day
                    }
                    , page: {
                        curr: 1
                    }
                });
            });

            //搜索重置
            form.on('submit(ams_reset)', function (data) {
                $("#search")[0].reset();
                var field = data.field;
                $.each(field, function (k, v) {
                    field[k] = '';
                });
                tableInit.reload({
                    where: {
                        username: field.username
                        , day: field.day
                    }
                    , page: {
                        curr: 1
                    }
                });
            });

            //搜索条件
            form.on('submit(ams_reset)', function (data) {
                $("#searchForm")[0].reset();
                form.render();
                $('#ams_search').trigger('click');
            });

            //标题搜索
            form.on('submit(ams_search)', function (data) {
                tableInit.reload({
                    where: data.field
                    , page: {
                        curr: 1
                    }
                });
            });


        })
    </script>


</body>

</html>
